package com.woniuxy.web.back;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniuxy.entity.Model;
import com.woniuxy.entity.ModelItem;
import com.woniuxy.entity.OrderItem;
import com.woniuxy.entity.ResponseEntity;
import com.woniuxy.entity.vo.VModelItem1;
import com.woniuxy.service.ModelItemService;
import com.woniuxy.service.ModelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("admin/modelItem")
@CrossOrigin(value="http://192.168.6.186:8080",allowCredentials = "true")
public class ModelItemController_b {
    @Autowired
    private ModelService modelService;
    @Autowired
    private ModelItemService modelItemService;

    @PostMapping("add")
    public ResponseEntity add(@RequestBody Model model){
        int modelId = modelService.getIdByName(model.getName());
        ModelItem m = model.getModelItem();
        ModelItem modelItem = new ModelItem();
        modelItem.setModelId(modelId);
        modelItem.setSpecName(m.getSpecName());
        modelItem.setSpecValue(m.getSpecValue());
        modelItemService.save(modelItem);
        return ResponseEntity.SUCCESS;
    }
    @PostMapping("list")
    public ResponseEntity list(@RequestBody Model model){
        List<ModelItem> modelItems = modelItemService.getByModelId(model.getId());
        return new ResponseEntity<List<ModelItem>>(modelItems);
    }

    @PostMapping("update")
    public void update(@RequestBody ModelItem modelItem){

            modelItemService.updateById(modelItem);
    }

//    @PostMapping("getByModelId")
//    public ResponseEntity<List<VModelItem1>> getByModelId(@RequestBody Model model){
//        List<VModelItem1> modelItemList = modelItemService.getVModelItems1ByModelId(model.getId());
//        return new ResponseEntity<List<VModelItem1>>(modelItemList);
//    }

    @PostMapping("getByModelId")
    public ResponseEntity<List<ModelItem>> getByModelId(@RequestBody Model model){
        return new ResponseEntity<List<ModelItem>>(modelItemService.getByModelId(model.getId()));
    }


}
